<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use Common\Controller\CommonController;
/**
 * 门店控制器
 *
 */
class StoreController extends HomeController {

	//系统首页
    public function index(){
        $brand = D("Brand")->limit(4)->select();
        $this->assign("brand",$brand);
        //查询出门店
        $bid = I("id",0,'intval');
        if(empty($bid)){
            $bid =$brand[0]["id"];
        }
        $where["bid"] =array("eq",$bid);
        C('LIST_ROWS',12);
        $store = $this->lists(D("Store"), $where, "sort,id desc", null, "id,sname,pic");
        foreach ($store as $key => $value) {
            if($value["pic"]!=null){
                $pic = explode(",", $value["pic"]);
                if($pic[0]!=null&&$pic[0]!=""){
                    $store[$key]["pic"]=$pic[0];
                }else{
                    $store[$key]["pic"]=$pic[1];
                }
            }

        }
        $this->assign("store", $store);
        $this->display();
    }
	public function detail(){
        $brand = D("Brand")->limit(4)->select();
        $this->assign("brand",$brand);
        $id = I("id",0,'intval');
        if($id==0){
            $this->error('不存在该门店！', U('Store/index'));
        }
        $where["id"] = array("eq",$id);
        $info = D("Store")->where($where)->find();
        if($info["pic"]!=null){
            $pic = explode(",", $info["pic"]);
            if($pic[0]!=null&&$pic[0]!=""){
                $info["cover"]=$pic[0];
            }else{
                $info["cover"]=$pic[1];
            }
            $info["pic"] =$pic;
        }
        $this->assign("info", $info);
        C('LIST_ROWS',6);
        $designer = $this->lists(D("Designer"), $where, "sort,id desc,status", null, "id,dname,status,job,cover");
        $this->assign("designer",$designer);
		$this->display();
	}

}